/**
 * Created by Administrator on 2016/7/25.
 */
(function () {
  'use strict';

  angular
    .module('client')
    .factory('indexService', indexService);

  indexService.$inject = [ '$cookies', '$localStorage', '$sessionStorage'];
  function indexService($cookies, $localStorage, $sessionStorage) {
    var services = {
      getDeviceSize: getDeviceSize,
      setDeviceSize: setDeviceSize,
      setLocalTime: setLocalTime,
      getLocalTime: getLocalTime,
      setDeviceModel: setDeviceModel,
      getDeviceModel: getDeviceModel,
      setDeviceInfo: setDeviceInfo,
      getDeviceInfo: getDeviceInfo,
      setToken: setToken,
      getToken: getToken,
      clearTimer: clearTimer,
      clearAll: clearAll,
    };
    return services;


    function getDeviceSize() {
      return {
        screenWidth: $sessionStorage.control_width,
        screenHeight: $sessionStorage.control_height,
      }
    }

    function setDeviceSize(w, h) {
      $sessionStorage.control_width = w;
      $sessionStorage.control_height = h;
    }

    function setLocalTime(localTime, duration) {
      $localStorage.localTime = localTime;
      $localStorage.duration = duration;
    }

    function getLocalTime() {
      return {
        localTime: $localStorage.localTime,
        duration: $localStorage.duration,
      }
    }

    function setDeviceModel(model) {
      $sessionStorage.deviceModel = model;
    }

    function getDeviceModel() {
      return $sessionStorage.deviceModel;
    }

    function setDeviceInfo(opts) {
      $sessionStorage.os = opts.os? 'Android ' + opts.os: opts.os;
      $sessionStorage.cpu = opts.cpu;
      $sessionStorage.cores = opts.cores;
      $sessionStorage.ram = opts.ram;
      $sessionStorage.resolution = opts.width + ' x ' +  opts.height;
    }

    function getDeviceInfo() {
      return {
        os: $sessionStorage.os,
        cpu: $sessionStorage.cpu,
        cores: $sessionStorage.cores,
        ram: $sessionStorage.ram,
        resolution: $sessionStorage.resolution,
      }
    }

    function setToken(remoteToken) {
      $localStorage.remoteToken = remoteToken;
    }

    function getToken() {
      return $localStorage.remoteToken;
    }

    function clearTimer() {
      delete $localStorage.duration;
      delete $localStorage.localTime;
    }

    function clearAll() {
      $localStorage.$reset();
    }
  }
})();
